
#include "Vector3d.h"
#include "RayTracer.h"
#include <iostream>
#include <time.h>
#include "VONode.h"
using namespace std;


RayTracer r(800,800);

void render()
{
	r.run();
}

int main()
{
	srand(time(0));
	sf::Sprite * sp;
	sf::Texture * tex = new sf::Texture();
	tex->LoadFromImage(r.image);
	sp = new sf::Sprite();
	sp->SetTexture(*tex);
	//sp->SetScale(2,2);
	
	sf::Thread th(render);
	th.Launch();
	
	
	sf::RenderWindow * renderWindow = new sf::RenderWindow(sf::VideoMode(800,800),"VoxelOctree by ZomBuster");

	while(renderWindow->IsOpen())
	{
		sf::Event Event;
		while (renderWindow->PollEvent(Event))
		{
			//todo
		}

		if(r.done)
		{
			renderWindow->Close();
		}

		if(rand() % 100 > 98)
		tex->LoadFromImage(r.image);
		renderWindow->Clear();
		renderWindow->Draw(*sp);
		renderWindow->Display();
	}
	delete renderWindow;
}